package com.itheima.cookie;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/*
    杀死Cookie
 */
@WebServlet("/servletDemo4")
public class ServletDemo4 extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 再创建一个同名的Cookie
        Cookie cookie = new Cookie("autoLogin","");

        // 设置持久化保存时间为0
        cookie.setMaxAge(0);

        // 设置相同的有效访问路径
        cookie.setPath(request.getContextPath());

        // 返回浏览器端覆盖原来的Cookie
        response.addCookie(cookie);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
